import cn.jja8.networkTransmission.DataClient;
import cn.jja8.networkTransmission.DataServices;
import cn.jja8.networkTransmission.GitPassageway;
import cn.jja8.networkTransmission.PutPassageway;

import java.io.IOException;
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;

class 发送{
    public static void main(String[] args) throws IOException {
        DataClient dataClient = new DataClient("127.0.0.1",12345);
        dataClient.开始接收数据();
        dataClient.打开get通道("666").发送get请求("给我哈哈哈".getBytes(StandardCharsets.UTF_8), new GitPassageway.GitReturn() {
            @Override
            public void 回复(byte[] b数据) {
                System.out.println(new String(b数据,StandardCharsets.UTF_8));
            }
        });
        dataClient.打开put通道("666").发送put请求("按时东方65速度方洒方5s".getBytes(StandardCharsets.UTF_8));
    }
}
class 接收{
    public static void main(String[] args) throws IOException {
        DataServices dataServices = new DataServices(InetAddress.getByName("127.0.0.1"), 12345, new DataServices.WhenConnected() {
            @Override
            public void 连接(DataClient 连接) {
                连接.打开put通道("666").setPut请求接收器(new PutPassageway.PutReceive() {
                    @Override
                    public void 新put请求(byte[] b数据, PutPassageway b通道) {
                        System.out.println(new String(b数据, StandardCharsets.UTF_8));
                    }
                });
                连接.打开get通道("666").setGit请求接收器(new GitPassageway.GitReceive() {
                    @Override
                    public void 新Git请求(byte[] b数据, GitPassageway.GitRequestReturn b数据返器, GitPassageway b通道) {
                        System.out.println(new String(b数据,StandardCharsets.UTF_8));
                        try {
                            b数据返器.返回数据("呵呵呵呵呵俄呵呵呵恶化".getBytes(StandardCharsets.UTF_8));
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        },10);
    }
}
